<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改商品分类')"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-productCategory-edit">
        <input id="id" name="id" type="hidden" th:value="${productId}"/>
        <div class="form-group">
            <label class="col-sm-2 control-label "><span style="color: red; ">*</span>所属分类：</label>
            <div class="col-sm-8">
                <div id="categoryTrees" class="ztree"></div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: summernote-js"/>
<th:block th:include="include :: ztree-js"/>

<script type="text/javascript">
    var prefix = ctx + "back/product";
    $(function () {
        var url = ctx + "back/productCategory/treeData?productId="+$('#id').val();
        var options = {
            id: "categoryTrees",
            url: url,
            check: {enable: true},
            expandLevel: 0
        };
        $.tree.init(options);
    });

    function submitHandler() {
        if ($.validate.form()) {
            let data = $('#form-productCategory-edit').serializeArray();
            data.push({"name": "categoryIds", "value": $.tree.getCheckedNodes()});
            $.operate.save(prefix + "/edit", data);
        }
    }
</script>
</body>
</html>